home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 August: Tool Chest / Apple_Developer_Group_August_1996_Tool_Chest.iso / Sample Code / Snippets / Sound / WaveTable Sounds / WaveTableSynthPlay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-11  |  1.7 KB  |  93 lines  |  [TEXT/MPS ]

  1. /*
  2.     WaveTableSynthPlay     12:32:47 PM  10/13/92 • Brigham Stevens
  3.     
  4.     Shows how to use the waveTableSynth
  5.     
  6.     InitDialogs is called only to install crash handler in case
  7.     no Debugger exists.
  8.  
  9.     BuildProgram WaveTableSynthPlay
  10. */
  11.  
  12. #include <Dialogs.h>
  13. #include <Sound.h>
  14. #include <Memory.h>
  15.  
  16. #define WAVE_SIZE (512*50)
  17.  
  18. void WaveTableSynthPlay()
  19. {
  20.     SndChannelPtr    chan;
  21.     SndCommand        mycmd;
  22.     unsigned char    *wave;
  23.     unsigned char    *waveSurfer;
  24.     short            soundByte;
  25.     short            change = 0;
  26.     short            err;
  27.     long            tickTime;
  28.  
  29.     /* Nab some memory for a waveTable to build our sound */
  30.     wave = (char *) NewPtr (WAVE_SIZE);
  31.     if(!wave) {
  32.         DebugStr("\pNewPtr failed to make wave...");
  33.         return;
  34.     }
  35.  
  36.     /* create a channel linked with the waveTableSynth */        
  37.     chan = nil;
  38.     err = SndNewChannel (&chan, waveTableSynth, initChan0, nil);
  39.     if (err) {
  40.         DebugStr("\p error SndNewChannel [1]");
  41.         goto bail;
  42.     }
  43.     
  44.     /* generate a cool wave */
  45.     waveSurfer = wave;
  46.     for (soundByte = 0; soundByte <= WAVE_SIZE; ++soundByte) {
  47.         *waveSurfer++ = change++;
  48.         if(change > WAVE_SIZE / 4) {
  49.             change += 44;
  50.         }
  51.     }
  52.     
  53.     /* install the wave */
  54.     mycmd.cmd = waveTableCmd;
  55.     mycmd.param1 = WAVE_SIZE;
  56.     mycmd.param2 = wave;
  57.     
  58.     err = SndDoImmediate (chan, &mycmd);
  59.     if (err) {
  60.         DebugStr("\p error SndDoImmediate [1]");
  61.         goto bail;
  62.     }
  63.  
  64.     /* play the wave */
  65.     mycmd.cmd = freqCmd;
  66.     mycmd.param1 = 0;
  67.     mycmd.param2 = 20;
  68.     
  69.     err = SndDoImmediate (chan, &mycmd);
  70.     if (err) {
  71.         DebugStr("\p error SndDoImmediate [2]");
  72.         goto bail;
  73.     }
  74.  
  75.     Delay(180,&tickTime);
  76.     
  77.     /* Now dump the channel */
  78.     err = SndDisposeChannel (chan,false);
  79.     if (err) {
  80.         DebugStr("\p error SndDisposeChannel [1]");
  81.         goto bail;
  82.     }
  83.  
  84. bail:
  85.     DisposePtr(wave);
  86. }
  87.  
  88.  
  89.  
  90. main()
  91. {
  92.     WaveTableSynthPlay();
  93. }